$(function () { 
	 
    $("[data-toggle='popover']").popover();
 	$("#btn_esAmount").click(function(){
 		 
 	});
});


	//关闭预计金额模态框
	$("#close_esAmount").click(function(){
		$("#esAmount").modal('hide');  
		 $("#esAmount").removeData('bs.modal');
	});
	//关闭预计销量模态框
	$("#close_esSale").click(function(){
		$("#esSale").modal('hide');
		 $("#esSale").removeData('bs.modal');
	});
	//保存预计金额模态框 inp_esAmount spa_esAmount sure_esAmount
	$("#sure_esAmount").click(function(){
		var money1 = $("#money_wan").val()+"万";
		
		/* var qua =$("#three_qua").val();
		
		$("#three_qua").val(qua+isZero(money1,"金额"));	 */
		$("#inp_esAmount").text(isZero(money1,"金额"));
		var hiddn = document.getElementById("spa_esAmount");
		hiddn.style.display="none";
		var show = document.getElementById("inp_esAmount");
		show.style.display="";
	 
		
		$("#esAmount").modal('hide');  
		 $("#esAmount").removeData('bs.modal');
	});
	//保存预计销量模态框 inp_esAmount spa_esAmount sure_esAmount
	$("#sure_esSale").click(function(){
		var money1 = $("#esSize").val()+"平米";
		
		
		
	/* 	var qua =$("#three_qua").val();
		$("#three_qua").val(qua+isZero(money1,"销量"));	 */
		  
		$("#inp_esSale").text(isZero(money1,"销量"));
		var hiddn = document.getElementById("spa_esSale");
		hiddn.style.display="none";
		 
		var show = document.getElementById("inp_esSale");
		show.style.display="";
		
		$("#esSale").modal('hide');  
		 $("#esSales").removeData('bs.modal');
	});






function isZero(value,type){
	var str="";
	if(value!="0"){
		str+=value;
		}
	switch (type) {
	case "金额":
		var money2=$("#money_qian").val();
		if(money2!="0"){
			str +=money2+"千";
		}
		break;
	case "销量":
	
		break;
	default:
		break;
	}
	
	return str;
		 
	 
}

//点击事件
//定性点击事件
$("#three_val1").click(function(){
	$(this).css('color','#000');
	$("#three_val2").css('color','#7F8C8D');
	$("#three_val3").css('color','#7F8C8D');
	$("#three_val").val("有价值");
	}
);
$("#three_val2").click(function(){
	$(this).css('color','#000');
	$("#three_val1").css('color','#7F8C8D');
	$("#three_val3").css('color','#7F8C8D');
	$("#three_val").val("无价值");
});
$("#three_val3").click(function(){
	$(this).css('color','#000');
	$("#three_val1").css('color','#7F8C8D');
	$("#three_val2").css('color','#7F8C8D');
	$("#three_val").val("不确定");
});
//定级点击事件
$("#three_level1").click(function(){
	$(this).css('color','#000');
	$("#three_level2").css('color','#7F8C8D');
	$("#three_level3").css('color','#7F8C8D');
	$("#three_level").val("大单");

});
$("#three_level2").click(function(){
	$(this).css('color','#000');
	$("#three_level1").css('color','#7F8C8D');
	$("#three_level3").css('color','#7F8C8D');
	$("#three_level").val("正常");

});
$("#three_level3").click(function(){
	$(this).css('color','#000');
	$("#three_level1").css('color','#7F8C8D');
	$("#three_level2").css('color','#7F8C8D');
	$("#three_level").val("小单");

});
//定量点击事件
$("#three_qua1").click(function(){
	$(this).css('color','#000');
	$("#three_qua2").css('color','#7F8C8D');
	$("#three_qua3").css('color','#7F8C8D');
	$("#three_qua4").css('color','#7F8C8D');
	var qua =$("#three_qua").val();
	$("#three_qua").val("本周"+qua);

});
$("#three_qua2").click(function(){
	$(this).css('color','#000');
	$("#three_qua1").css('color','#7F8C8D');
	$("#three_qua3").css('color','#7F8C8D');
	$("#three_qua4").css('color','#7F8C8D');
	 
	var qua =$("#three_qua").val();
	$("#three_qua").val("下周"+qua);

});
$("#three_qua3").click(function(){
	$(this).css('color','#000');
	$("#three_qua1").css('color','#7F8C8D');
	$("#three_qua2").css('color','#7F8C8D');
	$("#three_qua4").css('color','#7F8C8D');
	 
	var qua =$("#three_qua").val();
	$("#three_qua").val("本月"+qua);

});
$("#three_qua4").click(function(){
	$(this).css('color','#000');
	$("#three_qua1").css('color','#7F8C8D');
	$("#three_qua2").css('color','#7F8C8D');
	$("#three_qua3").css('color','#7F8C8D');
	var qua =$("#three_qua").val();
	$("#three_qua").val("下月"+qua);

});   
	
//关闭三一客模态框点击事件 close_thrOneModel 
$("#close_thrOneModel ").click(function(){
	$("#threeOne").modal('hide');
});

//保存三一客模态框点击事件 save_thrOneModel 
/**
 * $("#threeOne").modal('hide');  
 $("#threeOne").removeData('bs.modal');
 */
$("#save_thrOneModel ").click(function(){
	var determine = $("#three_val").val();
	var class1 = $("#three_level").val();
	var sale=$("#inp_esSale").text();
 	var acount=$("#inp_esAmount").text();
	var qua =$("#three_qua").val();
    var cussign = "预计"+qua;
	$("#three_qua").val("定性："+determine+"；定级："+class1+"；定量：预计"+qua.substring(0,2)+","+acount+","+sale);

    var three=[];
    var th = determine;
    three.push($('input[name="tbCustomerByCusId.cusId"]').val());
    three.push(determine);
    three.push(class1);
    three.push(cussign.substring(0,4));
	//获取表单数据 
	var form = $('#three_one_form');
	$.ajax({
		url : 'three/add_three',
		async : false,//同步，会阻塞操作
		type : 'POST',//PUT DELETE POST
		data : form.serialize(),
		contentType : 'application/x-www-form-urlencoded; charset=utf-8',
		dataType : 'json',
		success : function(s) {
			//var cusno =$("#threeCusno").val();
			if (s.code == 200) {
				
				/* $("#threeOne_div").load("http://localhost:8080/crmq/get-customer-view-by-no?cusno="+cusno+""); 
				$("#cus_view_dl").load("http://localhost:8080/crmq/get-customer-view-by-no?cusno="+cusno+""); */

			} else {
				swal("失败!", s.mgs, "error");
			}
		}
	});


    $.ajax({
        url : 'customer/save_three',
        async : false,//同步，会阻塞操作
        type : 'POST',//PUT DELETE POST
        data : {three:three},
        contentType : 'application/x-www-form-urlencoded; charset=utf-8',
        dataType : 'json',
        success : function(s) {
            //var cusno =$("#threeCusno").val();
            if (s.code == 200) {

                /* $("#threeOne_div").load("http://localhost:8080/crmq/get-customer-view-by-no?cusno="+cusno+"");
                $("#cus_view_dl").load("http://localhost:8080/crmq/get-customer-view-by-no?cusno="+cusno+""); */
                $('#threeOne').modal('hide');
                $("#threeOne").removeData(
                    "bs.modal");
                location.reload(true);
            } else {
                swal("失败!", s.mgs, "error");
            }
        }
    });
});


